package com.workflow.listener;

import com.gec.service.LeaveService;
import com.gec.utils.MyWebUtils;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

/**
 * @author Aniki
 * @date 2021-12-13
 */
public class LeaveEndHandler implements ExecutionListener {
    private LeaveService leaveService;
    public  LeaveEndHandler(){
        //装配service的Bean
        leaveService = MyWebUtils.getBean(LeaveService.class);
    }


    @Override
    public void notify(DelegateExecution exce) throws Exception {
        /**获取流程变量*/
        String isCancel = (String)exce.getVariable("cancel");
        String _status = "已办结";
        /**默认为已办结 根据cancel变量设置状态*/
        if ("true".equals(isCancel)) {
            _status = "已取消";
        }
        /**获取到流程实例ID*/
        String insId = exce.getProcessInstanceId();
        /**更新流程状态*/
        leaveService.updateStatusByInstance(insId,_status);

        /**更新办理人与任务ID 为null*/
        leaveService.updateAssigneeAndTask(insId,null,null);
    }
}
